package jy;

import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

import com.test.entity.Jiay;
import jdbc.DBUtil;

public class Test {
	private static Connection con = DBUtil.openConnection();
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		while(true){
			String in=scanner.next();
			if(in.lastIndexOf(",")==(in.length()-1)){
				in=in.substring(0,in.length()-1);
			}
			check(in);
			put(in);
		}
		
		//DBUtil.closeConnection();
	}
	
	public static List<String> check(String in) throws Exception{
		String sql = "SELECT * FROM jiay where id in("+in+")";
        List<Jiay> emList = DBUtil.queryBeanList(con, sql, Jiay.class);
        return printJiayList(emList);
	}
	
	public static void put(String in){
		String[] ids=in.split(",");
		for(String id:ids){
			String sql = "INSERT INTO jiay(id,time) VALUES("+id+",'"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"')";
			try {
				DBUtil.execute(con, sql);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	
	private static String printJiay(List<Jiay> jia) {
		if(jia!=null && !jia.isEmpty() && jia.get(0)!=null){
//			String outStr="var data=[";
			String outStr="";

			for(Jiay j:jia){
				outStr+=(j.getId()+",");
			}
			if(outStr.lastIndexOf(",")==(outStr.length()-1)){//去掉最后的逗号 例如: 1,2,3,
				outStr=outStr.substring(0,outStr.length()-1);
			}
//			System.out.println(outStr+"]");
			System.out.println(outStr);
			return outStr;
		}else {
			return "";
		}
    }
	
	private static List<String> printJiayList(List<Jiay> jia) {
		List<String> reData=new ArrayList<String>();
		if(jia!=null && !jia.isEmpty() && jia.get(0)!=null){
			for(Jiay j:jia){
				reData.add(j.getId()+"");
			}
			return reData;
		}else {
			return reData;
		}
    }
}
